package com.yellowpage.bigdata.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.opensymphony.xwork2.ActionContext;
import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;
import com.yellowpage.bigdata.data.NspOnofflogRequsetSum;
import com.yellowpage.bigdata.dao.NspOnofflogRequsetSumDao;
import com.yellowpage.ca.data.User;
import com.yellowpage.ca.service.RegionService;

public class NspOnofflogRequsetSumServiceImpl extends BaseServiceImpl implements NspOnofflogRequsetSumService {
	  private NspOnofflogRequsetSumDao nspOnofflogRequsetSumDao;
	  public void setNspOnofflogRequsetSumDao(NspOnofflogRequsetSumDao nspOnofflogRequsetSumDao) {
		  this.nspOnofflogRequsetSumDao = nspOnofflogRequsetSumDao;
	  }
	
	
	  /* Smooth generate Method */ 
	  public NspOnofflogRequsetSum getNspOnofflogRequsetSum(Long id){
	      return nspOnofflogRequsetSumDao.get(id);
	  }
	  
    public List<NspOnofflogRequsetSum> getAllNspOnofflogRequsetSum(){
        return nspOnofflogRequsetSumDao.getAll();
    }
    public List<Map> queryNspOnofflogRequsetSumByPage(Map queryMap, PageRender pageRender) {		
    	String t2 = queryMap.get("query_regionCode").equals("") ? "" : " and REGION_CODE in "+queryMap.get("query_regionCode");
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT a.LOG_DATE , a.REGION_CODE , a.APP_VERSION , a.OPERATOR , a.CHANNEL_NO , a.OPT_TYPE , a.CREATE_USER , a.CREATE_TIME , a.NOTE ," +
				" a.ONOFFLOG_REQUSET_SUM_ID , a.REQUEST_COUNT," +
				"(SELECT b.NAME FROM OMC_REGION b WHERE b.REGION_CODE = a.REGION_CODE) as REGION_NAME," +
				"(select b.NAME from OMC_DIC_TABLE b where b.VALUE = a.CHANNEL_NO and b.DIC_NAME='NSP_ONOFFLOG_CHANNEL_NO') as CHANNEL_NO_NAME" +
				"  FROM NSP_ONOFFLOG_REQUSET_SUM a WHERE 1=1 "+t2)
				    			.addCondition(" and a.LOG_DATE >= :logDate ")
				    			.addCondition(" and a.LOG_DATE <= :query_logDate_end ")
				    			.addCondition(" and a.APP_VERSION = :query_appVersion ")
				    			.addCondition(" and a.OPERATOR = :query_operator ")
				    			.addCondition(" and a.CHANNEL_NO = :query_channelNo ")
				    			.addCondition(" and a.OPT_TYPE = :query_optType ") ;


		List<Map> resultList;

		//当pageRender存在的时候，跳转
		if (pageRender != null)
		{ resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);}

		//否则取全量
		else

		{ resultList = sqlAssistant.query(
				baseDao.getConnection(), queryMap);}


		return resultList;
	}
    
    
    public void saveNspOnofflogRequsetSum(NspOnofflogRequsetSum nspOnofflogRequsetSum){
        nspOnofflogRequsetSumDao.save(nspOnofflogRequsetSum);
    }
    
	  public void updateNspOnofflogRequsetSum(NspOnofflogRequsetSum nspOnofflogRequsetSum){
	      nspOnofflogRequsetSumDao.update(nspOnofflogRequsetSum);
	  }
	  
	  public void delete(List deleteList){
	      nspOnofflogRequsetSumDao.remove(deleteList);
	  }
	  
	  
	 
	
}	